package music.dao;

import music.utils.dbcp.OracleDBCP;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * Created by pc01 on 11/6/2014.
 */
public class ZipcodeDAO {

    private static String selectZipcodeSQL = "select * from zipcode where dong like ?";

    public static String selectZipcode(String dong) {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        String result = "";


        try {
            conn = OracleDBCP.openDBCP();
            ps = conn.prepareStatement(selectZipcodeSQL);
            ps.setString(1, "%" + dong + "%");
            rs = ps.executeQuery();


            /*
            String ab = "      ";
            System.out.println("ㅋㅋ");
            System.out.println(ab.trim());
            System.out.println("요거사이ㅋㅋㅋㅋ");
            if(ab.trim()==null)
                System.out.println("우와 널이네");
            if(ab.trim()=="")
                System.out.println("우와 빈칸인가 그저");
            if(ab.trim()==" ")
                System.out.println("우와 한칸 빈칸인가 그저");
            if(ab.trim().isEmpty())
                System.out.println("우와 이즈 엠티인가 그저");
            */

            while (rs.next()) {
                result += "<option>"
                        + rs.getString(1).substring(0, 3) + "-"
                        + rs.getString(1).substring(3);
                for (int i = 3; i < 10; i++) {
                    if ( !rs.getString(i).equals(" "))
                        result += " " + rs.getString(i);
                }
                result += "</option><br/>";
            }


        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            OracleDBCP.closeDBCP(conn, ps, rs);
        }

        return result;

    }
}
